<?php
/**
 * 周舟 hzboye010@163.com
 * addby sublime snippets
 */
namespace app\index\domain;

use app\index\domain\BaseDomain;
use app\shop\api\BannersApi;
use app\shop\api\CategoryApi;
use app\shop\api\ProductApi;
use app\admin\api\ViewPageApi;

class AppDomain extends BaseDomain{
	protected $business_code = 'app';
	//获取APP页面总览
	public function queryPage(){
		if(IS_POST){
			$this->checkVersion(100);
			addLog("App/queryPage",$_GET,$_POST,"应用" . $this->client_id . "调用APP视图页面查询接口");
			$r = apiCall(ViewPageApi::QUERY_PAGE);
			if(!$r['status']) $this->apiReturnErr($r['info']);
			$this->apiReturnSuc($r['info']);
		}
	}
	//获取viewPage
	public function viewPage(){
		if(IS_POST){
			$this->checkVersion(100);
			addLog("App/viewPage",$_GET,$_POST,"应用" . $this->client_id . "调用APP视图查询接口");

			$page_id = $this->_post('page_id','','pageID缺失');
			$r = apiCall(ViewPageApi::GET_PAGE_INFO,[['id'=>$page_id]]);
			if(!$r['status']) $this->apiReturnErr($r['info']);
			$this->apiReturnSuc($r['info']);
		}
	}

	//app首页
	public function index(){
		if(IS_POST){
			$this->checkVersion(101);
			addLog("App/index",$_GET,$_POST,"应用" . $this->client_id . "调用APP首页接口");
			$info = [];
			//0.查询商品分类
			// $r = apiCall(CategoryApi::QUERY_NO_PAGING,[['parent'=>0,'level'=>1],"display_order asc",'id,name']);
			$r = apiCall(CategoryApi::GET_ALL);
			if(!$r['status']) $this->apiReturnErr($r['info']);
			$info['cate']  = $r['info'];
			// $info['cate_other']  = []; //更多
	//查询现有商品产销地 去掉中国142 dt_origin_country
			$r = apiCall(ProductApi::QUERY_ALL_COUNTRY);
			if(!$r['status']) $this->apiReturnErr($r['info']);
			// $this->apiReturnErr($r);
			$info['cate_golbal'] = $r['info']; //全球购
	//查询分组
			// //1.APP首页-顶轮播-6045
			// $r = apiCall(BannersApi::QUERY_NO_PAING,[['position'=>6045],"sort asc",'url,url_type,notes,img,title']);
			// if(!$r['status']) $this->apiReturnErr($r['info']);
			// $info['banner'] = $r['info'];
			// //2.APP首页-中推-6090
			// $r = apiCall(BannersApi::QUERY_NO_PAING,[['position'=>6090],"sort asc",'url,url_type,notes,img,title']);
			// if(!$r['status']) $this->apiReturnErr($r['info']);
			// $info['banner2'] = $r['info'];
			// //3.APP首页-产品分类-6079
			// $r = apiCall(BannersApi::QUERY_NO_PAING,[['position'=>6079],"sort asc",'url,url_type,notes,img,title']);
			// if(!$r['status']) $this->apiReturnErr($r['info']);
			// $info['p_cate'] = $r['info'];
			// //4.APP首页-孕婴好货-6080
			// $r = apiCall(BannersApi::QUERY_NO_PAING,[['position'=>6080],"sort asc",'url,url_type,notes,img,title']);
			// if(!$r['status']) $this->apiReturnErr($r['info']);
			// $info['p_baby'] = $r['info'];
			// //5.APP首页-热卖-16-17 - 商品分组
			// $info['p_hot'] = [];
			// $r = apiCall(BannersApi::GET_INFO,[['position'=>6075],"sort asc",'url,url_type,notes,img,title']);
			// if(!$r['status']) $this->apiReturnErr($r['info']);
			// $info['p_hot'][] = $r['info'];

			// $r = apiCall(BannersApi::GET_INFO,[['position'=>6046],"sort asc",'url,url_type,notes,img,title']);
			// if(!$r['status']) $this->apiReturnErr($r['info']);
			// $info['p_hot'][] = $r['info'];
			// //测试用 fix-待修复 - 商品分组
			// $p = [
			// 	"id"=> "3",
			// 	"name"=> "[测试商品]热门奶粉5段800g*3（24个月以上）",
			// 	"total_sales"=> "0",
			// 	"cate_id"=> "5",
			// 	"img"=> "124",
			// 	"price"=> "0.1",
			// 	"ori_price"=>"50",
			// ];

			// foreach ($info['p_hot'] as &$v) {
			// 	if(count($v)) $v['pro_list'] = [$p,$p,$p];//关联的商品列表
			// }
			$this->apiReturnSuc($info);
		}
  }
}